package StudyCode.summary.BufferAndChannel;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReadingChannelWithByteBuffer {
	public static void main(String[] argv) {
		try {
			ReadableByteChannel channel = new FileInputStream("E:/Copy/1.txt").getChannel();
			ByteBuffer buf = ByteBuffer.allocateDirect(10);
			int numRead = 0;
			while (numRead >= 0) {
				buf.rewind();
				numRead = channel.read(buf);
				buf.rewind();
				for (int i = 0; i < numRead; i++) {
					byte b = buf.get();
					System.out.println(b);
				}
			}
		} catch (Exception ignored) {
		}
	}
}
